package com.example.loginproject.tool

import android.animation.ObjectAnimator
import android.animation.ValueAnimator
import android.view.View
import androidx.core.animation.addListener

object AnimTools {
    fun startSwingAnim(view: View,
                       scope:Int = 10,
                       time:Long = 500,
                       onStart:()->Unit = {},
                       onEnd:()->Unit = {},
    ){
        val distance = view.dp2px(scope).toFloat()
      ObjectAnimator.ofFloat(view,"translationX",0f,-distance,2*distance,-distance).apply {
          duration = time
          repeatCount = 3
          repeatMode = ValueAnimator.RESTART
          start()
          //监听事件
        addListener ( onStart = {onStart()},onEnd = {onEnd()})
      }
    }
}